"""
常量定义文件
定义了数据库类型、脚本类型等常量
"""
import os

# 数据库类型
class DatabaseType:
    ICLAIM = "iclaim"
    CCLAIM = "cclaim"
    ADAPTER = "adapter"
    CLAIMWB = "claimwb"
    
    @classmethod
    def get_all(cls):
        """获取所有数据库类型"""
        return [cls.ICLAIM, cls.CCLAIM, cls.ADAPTER, cls.CLAIMWB]
    
    @classmethod
    def is_valid(cls, db_type):
        """验证数据库类型是否有效"""
        return db_type in cls.get_all()

# 脚本类型
class ScriptType:
    DDL = "DDL"
    DML = "DML"
    
    @classmethod
    def get_all(cls):
        """获取所有脚本类型"""
        return [cls.DDL, cls.DML]
    
    @classmethod
    def is_valid(cls, script_type):
        """验证脚本类型是否有效"""
        return script_type in cls.get_all()

# Excel列名定义
class ExcelColumns:
    REQUIREMENT_NO = "需求号"
    DATABASE = "数据库"
    SCRIPT_TYPE = "脚本类别"
    SQL_SCRIPT = "SQL脚本"
    REMARK = "备注"
    ROLLBACK_SCRIPT = "RollBack脚本"
    
    @classmethod
    def get_required_columns(cls):
        """获取必需的列名"""
        return [cls.REQUIREMENT_NO, cls.DATABASE, cls.SCRIPT_TYPE, cls.SQL_SCRIPT, cls.REMARK, cls.ROLLBACK_SCRIPT]

# GUI配置常量
class GUIConfig:
    WINDOW_TITLE = "Meiya SQL生成工具"
    WINDOW_WIDTH = 800
    WINDOW_HEIGHT = 600
    MIN_WIDTH = 600
    MIN_HEIGHT = 400
    
    # 颜色主题
    PRIMARY_COLOR = "#2b2b2b"
    SECONDARY_COLOR = "#3d3d3d"
    ACCENT_COLOR = "#1f538d"
    TEXT_COLOR = "#ffffff"
    
    # 文件配置
    APP_NAME = "MeiyaSQLTool"
    LOCAL_CONFIG_FILE = "config.json"
    SHARED_CONFIG_DIR = os.path.join(os.environ.get("APPDATA", os.path.expanduser("~")), "MeiyaSQLTool")
    SHARED_CONFIG_FILE = os.path.join(SHARED_CONFIG_DIR, "shared_config.json")
    SUPPORTED_FORMATS = [("Excel文件", "*.xlsx"), ("Excel文件", "*.xls"), ("所有文件", "*.*")]
    
    @classmethod
    def get_config_path(cls):
        """获取配置文件路径，优先使用共享配置"""
        # 确保共享配置目录存在
        if not os.path.exists(cls.SHARED_CONFIG_DIR):
            try:
                os.makedirs(cls.SHARED_CONFIG_DIR, exist_ok=True)
            except:
                # 如果无法创建共享目录，回退到本地配置
                return cls.LOCAL_CONFIG_FILE
        return cls.SHARED_CONFIG_FILE

# 消息常量
class Messages:
    SELECT_FILE_SUCCESS = "文件选择成功！"
    PARSE_SUCCESS = "Excel文件解析成功！"
    PARSE_ERROR = "Excel文件解析失败："
    FILE_NOT_FOUND = "文件不存在或无法访问！"
    INVALID_FORMAT = "Excel格式不正确，缺少必要的列："
    EMPTY_DATA = "Excel文件中没有数据！"
    INVALID_DATABASE = "无效的数据库类型："
    INVALID_SCRIPT_TYPE = "无效的脚本类型："
    EMPTY_REQUIRED_FIELD = "必填字段不能为空："
